use crate::util::*;

use aes::cipher::KeySizeUser;
use sha3::{Digest, Sha3_256};

// pub static KEY_SIZE: usize = 32;
lazy_static! {
    pub static ref KEY_SIZE: usize = aes::Aes256::key_size();
}

/// HMAC, general definition: https://tools.ietf.org/html/rfc2104
/// "To compute HMAC over the data `text' we perform
///  H(K XOR opad, H(K XOR ipad, text))"
/// Truncating HMACs is permissible.
pub fn hmac_sha3(key: &[u8], msg: &[u8]) -> Vec<u8> {
    // key size
    let ipad = vec![0x36; 32];
    let opad = vec![0x5C; 32];
    let mut hash_inner = Sha3_256::new();
    hash_inner.update(xor_blocks(key, &ipad[..]));
    hash_inner.update(msg);
    let result_inner = hash_inner.finalize();
    let mut hash_outer = Sha3_256::new();
    hash_outer.update(xor_blocks(key, &opad[..]));
    hash_outer.update(result_inner);
    let result_outer: Vec<u8> = hash_outer.finalize().to_vec();
    result_outer
}
